package com.example.service;

import cn.hutool.core.date.DateUtil;
import com.example.entity.Goodsorders;
import com.example.mapper.GoodsMapper;
import com.example.mapper.GoodsordersMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class GoodsordersService {

    @Resource
    private GoodsordersMapper goodsordersMapper;

    @Resource
    private GoodsMapper goodsMapper;

    public void add(Goodsorders goodsorders) {
        goodsorders.setOrderNum(DateUtil.format(new Date(), "yyyyMMddHHmmss"));
        goodsordersMapper.insert(goodsorders);
    }

    public PageInfo<Goodsorders> selectPage(Integer pageNum, Integer pageSize, Goodsorders goodsorders) {
        PageHelper.startPage(pageNum, pageSize);
        List<Goodsorders> list = goodsordersMapper.selectAll(goodsorders);
        return PageInfo.of(list);
    }

    public void update(Goodsorders goodsorders) {
        goodsordersMapper.updateById(goodsorders);
    }

    public void deleteById(Integer id) {
        goodsordersMapper.deleteById(id);
    }

    public List<Goodsorders> selectAll(Goodsorders goodsorders) {
        return goodsordersMapper.selectAll(goodsorders);
    }
}
